package org.dualr.litelog.servlet;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dualr.litelog.dao.PhotoDao;
import org.dualr.litelog.entity.Photo;

import com.google.appengine.api.datastore.Blob;

@SuppressWarnings("serial")
public class PhotoServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		String id = req.getParameter("id");
		if(id == null || "".equals(id)){
			return;
		}
		Photo photo = PhotoDao.getInstance().getById(Long.parseLong(id));
		if (photo == null){
			return;
		}
		Blob b = photo.getPhoto();
		resp.setContentType("image/jpeg;charset=utf-8");
		resp.getOutputStream().write(b.getBytes());
		resp.getOutputStream().close();
	}
}
